package com.zhl.config;

import feign.Feign;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.cloud.openfeign.Targeter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.DispatcherServlet;

public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor, ApplicationContextAware {
    private ApplicationContext applicationContext;
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        if ("FeignContext-123".equals(applicationContext.getId())){
            beanFactory.registerSingleton("LocalFeignMark", new LocalFeignMark());
        }

        DispatcherServlet dispatcherServlet = beanFactory.getBean(DispatcherServlet.class);

        //beanFactory.registerSingleton("customeFeignConfigure", new CustomeFeignConfigure());
        System.out.println(beanFactory.getBeanDefinitionNames());
//        beanFactory.
//        @Bean
//        public Targeter localFeignTargeter(DispatcherServlet dispatcherServlet){
//            return new LocalFeignTargeter(dispatcherServlet);
//        }
//
//        @Bean
//        public Feign.Builder build(){
//            return FeignLocal.builder();
//        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
